//
//  MSRoomConsumptionController.m
//  觅尚
//
//  Created by No.8 on 2019/3/29.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSRoomConsumptionController.h"
#import "MSDayCountCell.h"
#import "MSBigHeadNameButton.h"
#import "MSRoomConsumOtionCell.h"
#import "MSConsumptionModel.h"
#import "MSPrincessessModel.h"
#import "MSPreciousSaleInfoModel.h"
#import "MSRoomaiterModel.h"

@interface MSRoomConsumptionController ()<UITableViewDelegate,UITableViewDataSource>
{
    CustomNavigationBar *naviagtionBar;
}
/** 表视图*/
@property(nonatomic,strong)UITableView *tableView;

/** 公关头像和姓名*/
@property(nonatomic,strong)MSBigHeadNameButton *BigHeadNameButton;


/** 房间号  消费*/
@property(nonatomic,strong)NSString *totleCountLabel;



/** 房间号  消费*/
@property(nonatomic,strong)NSMutableArray *DataArray;


/** 房间号  消费*/
@property(nonatomic,strong)NSMutableArray *preciousSaleInfoArray;

/** 房间号  消费*/
@property(nonatomic,strong)NSMutableArray *MSPrincessessArray;

/** 状态*/
@property(nonatomic,strong)NSString *ConsumptionLabel;

/** 是否为招待房间*/
@property(nonatomic,strong)UILabel *EntertainLabel;

/** 是否为招待房间*/
@property(nonatomic,strong)NSString *HouseownerIMG;

/** 是否为招待房间*/
@property(nonatomic,strong)NSString *HouseownerLabel;

/** 是否为招待房间*/
@property(nonatomic,strong)NSString *WaiterIMG;

/** 是否为招待房间*/
@property(nonatomic,strong)NSString *WaiterNameLabel;

/** <#name#>*/
@property(nonatomic,strong)NSString *CurrentConsumptionView;


@end

@implementation MSRoomConsumptionController
- (int)navBarBottom {
    if ([WRNavigationBar isIphoneX]) {
        return 88;
    } else {
        return 64;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    self.DataArray = [NSMutableArray new];
    self.preciousSaleInfoArray = [NSMutableArray new];
    self.MSPrincessessArray = [NSMutableArray new];
    Prepare *header = [Prepare headerWithRefreshingTarget:self refreshingAction:@selector(MJChiBaoZiHeaderRefresh)];
    // 隐藏时间
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.hidden = YES;
    // 马上进入刷新状态
    self.tableView.mj_header = header;
    [self.tableView.mj_header beginRefreshing];
    //     [self ReloadData];
}
- (void)MJChiBaoZiHeaderRefresh{
    
    [self ReloadData];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self CreateNavigationBar];
    
    
    
    
    [self tableView];
    
}
/** 表视图*/
- (UITableView *)tableView{
    self.extendedLayoutIncludesOpaqueBars = YES;
    if (!_tableView) {
        
        if (@available(iOS 11.0, *)) {
            
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            
        } else {
            
            self.automaticallyAdjustsScrollViewInsets = NO;
            
        }
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, [self navBarBottom], ScreenWidth, ScreenHeight - [self navBarBottom] ) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:self.tableView];
    }
    return _tableView;
}
- (void)ReloadData{
    [self.DataArray removeAllObjects];
    [self.preciousSaleInfoArray removeAllObjects];
    [self.MSPrincessessArray removeAllObjects];
    if ([self.Tagstr isEqualToString:@"1"]) {
        NSDictionary * params = @{@"openid":self.openid,@"uid":[WYCAccountTool unarchiveuid]};
        [HTTPRequest POST:MSgetByIdConsumptionRoom params:params succeed:^(id responseObject) {
            //        WYCLog(@"-----------%@",params);
            //        WYCLog(@"-----------%@",responseObject);
            if (CodeStr) {
                for (NSDictionary * dict in responseObject[@"data"]) {
                    [self.tableView.mj_header endRefreshing];
                    MSConsumptionModel * model = [MSConsumptionModel mj_objectWithKeyValues:dict];
                    [self.DataArray addObject:model];
                    //                self.preciousSaleInfoArray addObject:dict[@""]
                    self.totleCountLabel = [NSString stringWithFormat:@"房间%@     ￥%@",model.roomName,model.money];
                    if (dict[@"houseOwner"] != nil || dict[@"houseOwner"] != NULL || ![dict[@"houseOwner"] isKindOfClass:[NSNull class]] || [[dict[@"houseOwner"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] != 0){
                        self.HouseownerIMG = [NSString stringWithFormat:@"%@",dict[@"houseOwner"][@"avatarUrl"]];
                    }else{
                        
                        self.HouseownerIMG = @"";
                    }
                    if (dict[@"houseOwner"] != nil || dict[@"houseOwner"] != NULL || ![dict[@"houseOwner"]isKindOfClass:[NSNull class]] || [[dict[@"houseOwner"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] != 0){
                        self.HouseownerLabel = [NSString stringWithFormat:@"%@",dict[@"houseOwner"][@"userName"]];
                    }else{
                        self.HouseownerLabel = @"";
                    }
                    
                    self.CurrentConsumptionView = [NSString stringWithFormat:@"%@",model.sumMoney];
                    self.MSPrincessessArray = [MSPrincessessModel mj_objectArrayWithKeyValuesArray:model.princessess];
                    self.preciousSaleInfoArray = [MSPreciousSaleInfoModel mj_objectArrayWithKeyValuesArray:model.preciousSaleInfo];
                    for (NSDictionary * dict  in model.waiter) {
                        self.WaiterIMG = [NSString stringWithFormat:@"%@",dict[@"avatarUrl"]];
                        self.WaiterNameLabel = [NSString stringWithFormat:@"%@",dict[@"userName"]];
                        
                    }
                    
                    
                    
                    if ([model.roomState intValue] == 0){
                        self.ConsumptionLabel = [NSString stringWithFormat:@"空闲"];
                    }else if ([model.roomState intValue] == 1) {
                        self.ConsumptionLabel = [NSString stringWithFormat:@"开房"];
                    }else if ([model.roomState intValue] == 2){
                        self.ConsumptionLabel = [NSString stringWithFormat:@"预定"];
                    }else{
                        self.ConsumptionLabel = [NSString stringWithFormat:@"超消费"];
                    }
                    if ([model.isEntertain intValue] == 0) {
                        self.EntertainLabel.hidden = YES;
                    }else{
                        self.EntertainLabel.hidden = NO;
                    }
                }
                
                
            }else{
                [self.tableView.mj_header endRefreshing];
                [MBManager showBriefAlert:responseObject[@"msg"]];
            }
            [self CreatView];
            [self.tableView reloadData];
        } failure:^(NSError *error) {
            [self.tableView.mj_header endRefreshing];
            [MBManager showBriefAlert:Failed];
        }];
    }else{
        NSDictionary * params = @{@"roomId":self.roomID,@"uid":[WYCAccountTool unarchiveuid]};
        [HTTPRequest POST:MSgetByIdRoom params:params succeed:^(id responseObject) {
            //        WYCLog(@"-----------%@",params);
                    WYCLog(@"responseObject-----------%@",responseObject);
            if (CodeStr) {
                
                
                for (NSDictionary * dict in responseObject[@"data"]) {
                    [self.tableView.mj_header endRefreshing];
                    MSConsumptionModel * model = [MSConsumptionModel mj_objectWithKeyValues:dict];
                    [self.DataArray addObject:model];
                    self.totleCountLabel = [NSString stringWithFormat:@"房间%@     ￥%@",model.roomName,model.money];
                    
                    self.HouseownerIMG = [NSString stringWithFormat:@"%@",dict[@"houseOwner"][@"avatarUrl"]];
                    self.HouseownerLabel = [NSString stringWithFormat:@"%@",dict[@"houseOwner"][@"userName"]];
                    self.CurrentConsumptionView = [NSString stringWithFormat:@"%@",model.sumMoney];
                    self.MSPrincessessArray = [MSPrincessessModel mj_objectArrayWithKeyValuesArray:model.princessess];
                    self.preciousSaleInfoArray = [MSPreciousSaleInfoModel mj_objectArrayWithKeyValuesArray:model.preciousSaleInfo];
                    for (NSDictionary * dict  in model.waiter) {
                        self.WaiterIMG = [NSString stringWithFormat:@"%@",dict[@"avatarUrl"]];
                        self.WaiterNameLabel = [NSString stringWithFormat:@"%@",dict[@"userName"]];
                        
                    }
                    
                    WYCLog(@"---------------%@",model.roomState);
                    
                    if ([model.roomState intValue] == 0){
                        self.ConsumptionLabel = [NSString stringWithFormat:@"空闲"];
                    }else if ([model.roomState intValue] == 1) {
                        self.ConsumptionLabel = [NSString stringWithFormat:@"开房"];
                    }else if ([model.roomState intValue] == 2){
                        self.ConsumptionLabel = [NSString stringWithFormat:@"预定"];
                    }else{
                        self.ConsumptionLabel = [NSString stringWithFormat:@"超消费"];
                    }
                    if ([model.isEntertain intValue] == 0) {
                        self.EntertainLabel.hidden = YES;
                    }else{
                        self.EntertainLabel.hidden = NO;
                    }
                }
                
                
            }else{
                [self.tableView.mj_header endRefreshing];
                [MBManager showBriefAlert:responseObject[@"msg"]];
            }
            [self CreatView];
            [self.tableView reloadData];
        } failure:^(NSError *error) {
            [self.tableView.mj_header endRefreshing];
            [MBManager showBriefAlert:Failed];
        }];
    }
    
}
/** 创建表头*/
- (void)CreatView{
    UIView * HeaderView = [[UIView alloc] init];
    HeaderView.x = 0;
    HeaderView.x = 0;
    HeaderView.width = ScreenWidth;
    HeaderView.backgroundColor = backgroundcolor;
    
    //    self.CollectionHeaderView = HeaderView;
    
    /** 房间总量*/
    UILabel * totleCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(40 * px, 40 * px, ScreenWidth / 3 * 2, 80 * px)];
    totleCountLabel.textColor = [UIColor whiteColor];
    totleCountLabel.text = [NSString stringWithFormat:@"%@",self.totleCountLabel];
    totleCountLabel.textAlignment = NSTextAlignmentLeft;
    totleCountLabel.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
    [HeaderView addSubview:totleCountLabel];
//    self.totleCountLabel = totleCountLabel;
    
    
    /** 超消费标签*/
    UILabel * ConsumptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth - 380 * px, totleCountLabel.y, 150 * px, totleCountLabel.height)];
    ConsumptionLabel.textColor = [UIColor whiteColor];
    ConsumptionLabel.text = [NSString stringWithFormat:@"%@",self.ConsumptionLabel];
    ConsumptionLabel.textAlignment = NSTextAlignmentCenter;
    ConsumptionLabel.layer.cornerRadius = 30 * px;
    ConsumptionLabel.backgroundColor = WYCRGBColor(224, 93, 49);
    ConsumptionLabel.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
    [HeaderView addSubview:ConsumptionLabel];
//    self.ConsumptionLabel = ConsumptionLabel;
    
    
//    /** 招待标签*/
//    UILabel * EntertainLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(ConsumptionLabel.frame) + 20 * px, totleCountLabel.y, ConsumptionLabel.width, totleCountLabel.height)];
////    EntertainLabel.backgroundColor = [UIColor whiteColor];
//    EntertainLabel.textColor = [UIColor whiteColor];
//    EntertainLabel.text = @"招待";
//    EntertainLabel.textAlignment = NSTextAlignmentCenter;
////    EntertainLabel.layer.cornerRadius = 20 * px;
//    EntertainLabel.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
//
//
//    CAGradientLayer *gradientLayer =  [CAGradientLayer layer];
//    gradientLayer.frame = EntertainLabel.bounds;
//    gradientLayer.cornerRadius = 10 * px;
//    gradientLayer.startPoint = CGPointMake(0, 0);
//    //        gradientLayer
//    gradientLayer.endPoint = CGPointMake(1, 0);
//    gradientLayer.locations = @[@(0.2),@(1.0)];//渐变点
//    [gradientLayer setColors:@[(id)[WYCRGBColor(96, 59, 152) CGColor],(id)[WYCRGBColor(202, 72, 114) CGColor]]];//渐变数组
//    [EntertainLabel.layer addSublayer:gradientLayer];
//    [HeaderView addSubview:EntertainLabel];
//    self.EntertainLabel = EntertainLabel;
    
    UIView * timeView = [[UIView alloc] initWithFrame:CGRectMake(totleCountLabel.x, CGRectGetMaxY(totleCountLabel.frame) + 60 * px, ScreenWidth * 0.4, 80 * px)];
    timeView.layer.cornerRadius = 10 * px;
    timeView.layer.borderWidth = 1;
    timeView.layer.borderColor = WYCRGBColor(33, 46, 45).CGColor;
    [HeaderView addSubview:timeView];
    
    
    
    /** 日历图标*/
    UIButton * TimeButton = [[UIButton alloc] initWithFrame:CGRectMake(30 * px, 10 * px, 60 * px, 60 * px)];
    //    [TimeButton setImage:[UIImage imageNamed:@"calendar icon"] forState:UIControlStateNormal];
    [TimeButton setBackgroundImage:[UIImage imageNamed:@"calendar icon"] forState:UIControlStateNormal];
    TimeButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
    //    TimeButton.backgroundColor = [UIColor redColor];
    [timeView addSubview:TimeButton];
    
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    [formatter1 setDateFormat:@"yyyy.MM.dd"];
    NSDate *datenow = [NSDate date];
    NSString *currentTimeString1 = [formatter1 stringFromDate:datenow];
    /** 时间*/
    UILabel * timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(TimeButton.frame) + 40 * px, TimeButton.y, timeView.width / 1.5, TimeButton.height)];
    timeLabel.textColor = [UIColor grayColor];
    if ([self.Tagstr isEqualToString:@"1"]) {
        timeLabel.text = [NSString stringWithFormat:@"%@",self.opentime];
    }else{
        timeLabel.text = [NSString stringWithFormat:@"%@",currentTimeString1];
    }
        timeLabel.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
    [timeView addSubview:timeLabel];
    
    //f当前消费View
    UIView *CurrentConsumptionView = [[UIView alloc] init];
    CurrentConsumptionView.x = timeView.x;
    CurrentConsumptionView.y = CGRectGetMaxY(timeView.frame) + 40 * px;
    CurrentConsumptionView.width = ScreenWidth - 80 * px;
    CurrentConsumptionView.backgroundColor = BackViewColor;
    

    
    /** 当前消费标签*/
    UILabel * CurrentConsumptionTitle = [[UILabel alloc] initWithFrame:CGRectMake(20 * px, 40 * px, 250 * px, 60 * px)];
    CurrentConsumptionTitle.textColor = [UIColor blackColor];
    CurrentConsumptionTitle.text = @"当前消费";
    CurrentConsumptionTitle.textAlignment = NSTextAlignmentCenter;
    CurrentConsumptionTitle.layer.cornerRadius = 15 * px;
    CurrentConsumptionTitle.backgroundColor = WYCRGBColor(95, 207, 185);
    CurrentConsumptionTitle.font = [UIFont systemFontOfSize:SYRealValue(26 / 2)];
    [CurrentConsumptionView addSubview:CurrentConsumptionTitle];
    
    
    
    /** 当前消费标签*/
    UILabel * CurrentConsumptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(CurrentConsumptionTitle.x, CGRectGetMaxY(CurrentConsumptionTitle.frame) + 10 * px, 350 * px, 60 * px)];
    CurrentConsumptionLabel.textColor = [UIColor whiteColor];
    CurrentConsumptionLabel.text = [NSString stringWithFormat:@"￥%@",self.CurrentConsumptionView];
//    CurrentConsumptionLabel.textAlignment = NSTextAlignmentCenter;
    CurrentConsumptionLabel.layer.cornerRadius = 15 * px;
//    CurrentConsumptionLabel.backgroundColor = WYCRGBColor(95, 207, 185);
    CurrentConsumptionLabel.font = [UIFont systemFontOfSize:SYRealValue(36 / 2)];
    [CurrentConsumptionView addSubview:CurrentConsumptionLabel];
    /********************开房人********/
    //开房人
    UILabel *HouseownerTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CurrentConsumptionLabel.x, CGRectGetMaxY(CurrentConsumptionLabel.frame) + 40 * px, 150 * px, 60 * px)];
    HouseownerTitleLabel.text = @"开房人:";
    HouseownerTitleLabel.textColor = CurrentConsumptionLabel.textColor;
    HouseownerTitleLabel.textAlignment = NSTextAlignmentLeft;
    HouseownerTitleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [CurrentConsumptionView addSubview:HouseownerTitleLabel];
    
    /** 开房人头像*/
    UIImageView *HouseownerIMG = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(HouseownerTitleLabel.frame) + 10 * px, HouseownerTitleLabel.y - 10 * px, 80 * px, 80 * px)];
    HouseownerIMG.layer.cornerRadius = 40 * px;
//    if (self.HouseownerIMG == nil || self.HouseownerIMG == NULL || [self.HouseownerIMG isKindOfClass:[NSNull class]] || [[self.HouseownerIMG stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
//        HouseownerIMG.image = [UIImage imageNamed:@""];
//    }else{
    [HouseownerIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.HouseownerIMG]]];
//    }
    HouseownerIMG.layer.masksToBounds = YES;
    HouseownerIMG.backgroundColor = BackViewColor;
    [CurrentConsumptionView addSubview:HouseownerIMG];
//    self.HouseownerIMG = HouseownerIMG;
    
    
    /** 开房人姓名*/
    UILabel *HouseownerLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(HouseownerIMG.frame) + 10 * px, HouseownerTitleLabel.y, 200 * px, 60 * px)];

    HouseownerLabel.text = [NSString stringWithFormat:@"%@",self.HouseownerLabel];
//    }
    HouseownerLabel.textColor = [UIColor grayColor];
    HouseownerLabel.font = [UIFont systemFontOfSize:SYRealValue(26 / 2)];
    [CurrentConsumptionView addSubview:HouseownerLabel];
    
    
    
    /** 线*/
    UIView * houseLine = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(HouseownerIMG.frame) + 20 * px, CurrentConsumptionView.width, 1)];
    houseLine.backgroundColor = [UIColor darkGrayColor];
    [CurrentConsumptionView addSubview:houseLine];
    /********************服务生********/
    
    //服务生
    UILabel *WaiterTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CurrentConsumptionLabel.x, CGRectGetMaxY(houseLine.frame) + 40 * px, HouseownerTitleLabel.width, HouseownerTitleLabel.height)];
    WaiterTitleLabel.text = @"服务生:";
    WaiterTitleLabel.textColor = CurrentConsumptionLabel.textColor;
    WaiterTitleLabel.textAlignment = NSTextAlignmentLeft;
    WaiterTitleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [CurrentConsumptionView addSubview:WaiterTitleLabel];



    /** 服务生头像*/
    UIImageView *WaiterIMG = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(WaiterTitleLabel.frame) + 10 * px, WaiterTitleLabel.y - 10 * px, HouseownerIMG.width, HouseownerIMG.height)];
    WaiterIMG.backgroundColor = [UIColor clearColor];
    WaiterIMG.layer.cornerRadius = 40 * px;
    if (self.WaiterIMG == nil || self.WaiterIMG == NULL || [self.WaiterIMG isKindOfClass:[NSNull class]] || [[self.WaiterIMG stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
        WaiterIMG.image = [UIImage imageNamed:@""];
    }else{
        [WaiterIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.WaiterIMG]]];
    }
    
    WaiterIMG.backgroundColor = BackViewColor;
    WaiterIMG.layer.masksToBounds = YES;
//    WaiterIMG.image = [UIImage imageNamed:@"chaoxiaofei"];
    [CurrentConsumptionView addSubview:WaiterIMG];

    /** 服务生姓名*/
    UILabel * WaiterNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(WaiterIMG.frame) + 10 * px, WaiterTitleLabel.y, HouseownerLabel.width, HouseownerLabel.height)];
    if (self.WaiterNameLabel == nil || self.WaiterNameLabel == NULL || [self.WaiterNameLabel isKindOfClass:[NSNull class]] || [[self.WaiterNameLabel stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
        WaiterNameLabel.text = @"";
    }else{
        WaiterNameLabel.text = [NSString stringWithFormat:@"%@",self.WaiterNameLabel];
    }
    
    WaiterNameLabel.textColor = [UIColor grayColor];
    WaiterNameLabel.font = [UIFont systemFontOfSize:SYRealValue(26 / 2)];
    [CurrentConsumptionView addSubview:WaiterNameLabel];
    
    /** 线*/
    UIView * WaiterLine = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(WaiterIMG.frame) + 20 * px, CurrentConsumptionView.width, 1)];
    WaiterLine.backgroundColor = [UIColor darkGrayColor];
    [CurrentConsumptionView addSubview:WaiterLine];
    
    
    /********************公关********/

    //公关
    UILabel *RelationsTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CurrentConsumptionLabel.x, CGRectGetMaxY(WaiterNameLabel.frame) + 70 * px, HouseownerTitleLabel.width, HouseownerTitleLabel.height)];
    RelationsTitleLabel.text = @"公   关:";
    RelationsTitleLabel.textColor = CurrentConsumptionLabel.textColor;
    RelationsTitleLabel.textAlignment = NSTextAlignmentLeft;
    RelationsTitleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [CurrentConsumptionView addSubview:RelationsTitleLabel];

    UIView *RelationsView = [[UIView alloc] init];
    RelationsView.x = CGRectGetMaxX(RelationsTitleLabel.frame) + 10 * px;
    RelationsView.y = CGRectGetMaxY(RelationsTitleLabel.frame);
    RelationsView.width = CurrentConsumptionView.width - RelationsTitleLabel.width - 100 * px;
    RelationsView.backgroundColor = [UIColor clearColor];
    

    int totalColumns = 3;
    //每行列数

    CGFloat W = 210 * px;
    CGFloat H = 110 * px;

    //    间隙
    CGFloat margin = (RelationsView.width - totalColumns * W) / (totalColumns + 1);
    for (int i = 0; i < self.MSPrincessessArray.count; i ++) {
        
        MSPrincessessModel * model = self.MSPrincessessArray[i];
        //创建按钮
        self.BigHeadNameButton = [[MSBigHeadNameButton alloc] init];
        /** 公关头像姓名*/

        int row = i / totalColumns;
        int col = i % totalColumns;
        //根据行号和列号来确定 子控件的坐标
        CGFloat cellX = margin + col * (W + margin);
        CGFloat cellY = row * (H + margin);

        self.BigHeadNameButton = [[MSBigHeadNameButton alloc] initWithFrame:CGRectMake(cellX, cellY, W, H)];
        
//        [self.BigHeadNameButton  setImage:[UIImage imageNamed:@"chaoxiaofei" ] forState:UIControlStateNormal];
        if (model.avatarUrl == nil || model.avatarUrl == NULL || [model.avatarUrl isKindOfClass:[NSNull class]] || [[model.avatarUrl stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
            self.BigHeadNameButton.imageView.backgroundColor = [UIColor clearColor];
        }else{
            [self.BigHeadNameButton sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",model.avatarUrl]] forState:UIControlStateNormal];
        }
        
        if (model.userName == nil || model.userName == NULL || [model.userName isKindOfClass:[NSNull class]] || [[model.userName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
            [self.BigHeadNameButton setTitle:@"" forState:UIControlStateNormal];
        }else{
            [self.BigHeadNameButton setTitle:model.userName forState:UIControlStateNormal];
        }
//        self.BigHeadNameButton.layer.cornerRadius = 40 * px;
//        self.BigHeadNameButton.layer.masksToBounds = YES;
        //        self.HeadNameButton.backgroundColor = [UIColor redColor];
        self.BigHeadNameButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(26 / 2)];
        [self.BigHeadNameButton  setTitleColor:HouseownerLabel.textColor forState:UIControlStateNormal];
        [RelationsView  addSubview:self.BigHeadNameButton];
    }
    RelationsView.height = CGRectGetMaxY(self.BigHeadNameButton.frame) + 20 * px;
    [CurrentConsumptionView addSubview:RelationsView];
    CurrentConsumptionView.height = CGRectGetMaxY(RelationsView.frame);
    [HeaderView addSubview:CurrentConsumptionView];
    
    
    
    /** 日历按钮*/
    UIImageView * titleIMG = [[UIImageView alloc] initWithFrame:CGRectMake(CurrentConsumptionView.x, CGRectGetMaxY(CurrentConsumptionView.frame) + 60 * px, 60 * px, 60 * px)];
    titleIMG.image = [UIImage imageNamed:@"消费"];
    titleIMG.layer.cornerRadius = 30 * px;
    [HeaderView addSubview:titleIMG];
    
    
    /** 消费详情标题*/
    UILabel * Consumptiondetails = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(titleIMG.frame) + 20 * px, titleIMG.y, 200 * px, titleIMG.height)];
    Consumptiondetails.textColor = BackViewColor;
    Consumptiondetails.text = @"消费详情";
    Consumptiondetails.textAlignment = NSTextAlignmentLeft;
    Consumptiondetails.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
    [HeaderView addSubview:Consumptiondetails];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"HH:mm"];
    NSDate *datenow1 = [NSDate date];
    NSString *currentTimeString = [formatter stringFromDate:datenow1];
    /** 消费详情标题*/
    UILabel * updatetimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(HeaderView.width - 440 * px, titleIMG.y, 400 * px, titleIMG.height)];
    updatetimeLabel.textColor = WYCRGBColor(74, 161, 164);
    updatetimeLabel.text = [NSString stringWithFormat:@"更新时间%@",currentTimeString];
    updatetimeLabel.textAlignment = NSTextAlignmentLeft;
    updatetimeLabel.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
    [HeaderView addSubview:updatetimeLabel];
    
    UIView * titleView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleIMG.frame) + 30 * px, HeaderView.width, 120 * px)];
    titleView.backgroundColor = BackViewColor;
    [HeaderView addSubview:titleView];
    NSArray * titleArray = @[@"图片",@"名称",@"单价",@"数量",@"总价"];
    
    CGFloat CommoditytitleWidth = HeaderView.width / titleArray.count;
    CGFloat CommoditytitleY = 0;
    CGFloat CommoditytitleHeight = titleView.height;
    for (int index = 0; index < titleArray.count; index ++) {
        /** 标题label*/
        UILabel * Commoditytitle = [[UILabel alloc] init];
        Commoditytitle.x = CommoditytitleWidth * index;
        Commoditytitle.y = CommoditytitleY;
        Commoditytitle.width = CommoditytitleWidth;
        Commoditytitle.height = CommoditytitleHeight;
        Commoditytitle.textColor = WYCRGBColor(102, 121, 145);
        Commoditytitle.text = titleArray[index];
        Commoditytitle.textAlignment = NSTextAlignmentCenter;
        Commoditytitle.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
        [titleView addSubview:Commoditytitle];
    }
    
    
    HeaderView.height = CGRectGetMaxY(titleView.frame);
    [self.view addSubview:HeaderView];
    
    self.tableView.tableHeaderView = HeaderView;
    
}

- (void)CreateNavigationBar{
    
    self.view.backgroundColor = backgroundcolor;
    naviagtionBar = [[CustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [self navBarBottom])];
    [self.view addSubview:naviagtionBar];
    naviagtionBar.titleLabel.text = @"房间消费详细";
    naviagtionBar.rightBtn.hidden = YES;
    naviagtionBar.rightBtnTitle.hidden = YES;
    [self.view addSubview:naviagtionBar];
    
    [naviagtionBar.leftBtn setImage:[UIImage imageNamed:@"左箭头"] forState:UIControlStateNormal];
    [naviagtionBar.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.preciousSaleInfoArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 140 * px;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    MSRoomConsumOtionCell * cell = [MSRoomConsumOtionCell cellWithTableView:tableView];
    tableView.backgroundColor = [UIColor clearColor];
    //无色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.PrincessessModel = self.preciousSaleInfoArray[indexPath.row];
    //    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}


- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:NO];
}
@end
